package com.wgh.product.api.client;

import com.wgh.common.vo.Result;
import com.wgh.product.dto.ProductRelationDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品关联服务客户端
 * 用于其他服务调用商品关联服务的API
 */
@FeignClient(name = "shop-product", path = "/api/product-relation")
public interface ProductRelationClient {

    /**
     * 根据主商品ID和关联类型查询关联商品列表
     */
    @GetMapping("/main-product/{mainProductId}/type/{relationType}")
    Result<List<ProductRelationDTO>> getRelationsByMainProductIdAndType(
            @PathVariable Long mainProductId,
            @PathVariable Integer relationType);

    /**
     * 根据关联商品ID和关联类型查询关联记录
     */
    @GetMapping("/related-product/{relatedProductId}/type/{relationType}")
    Result<List<ProductRelationDTO>> getRelationsByRelatedProductIdAndType(
            @PathVariable Long relatedProductId,
            @PathVariable Integer relationType);

    /**
     * 批量添加商品关联
     */
    @PostMapping("/batch")
    Result<Boolean> addBatch(@RequestBody List<ProductRelationDTO> productRelationDTOs);

    /**
     * 根据主商品ID删除商品关联
     */
    @DeleteMapping("/main-product/{mainProductId}")
    Result<Boolean> deleteByMainProductId(@PathVariable Long mainProductId);

    /**
     * 根据主商品ID和关联类型删除商品关联
     */
    @DeleteMapping("/main-product/{mainProductId}/type/{relationType}")
    Result<Boolean> deleteByMainProductIdAndType(
            @PathVariable Long mainProductId,
            @PathVariable Integer relationType);

    /**
     * 检查商品关联是否存在
     */
    @GetMapping("/check")
    Result<Boolean> checkRelationExists(
            @RequestParam Long mainProductId,
            @RequestParam Long relatedProductId,
            @RequestParam Integer relationType);

    /**
     * 添加单条商品关联
     */
    @PostMapping
    Result<Boolean> addProductRelation(@RequestBody ProductRelationDTO productRelationDTO);

    /**
     * 根据ID删除商品关联
     */
    @DeleteMapping("/{id}")
    Result<Boolean> deleteProductRelation(@PathVariable Long id);
}